home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / pcl4b42 / modem_io.bas < prev    next >
Encoding:
BASIC Source File  |  1995-05-09  |  3.5 KB  |  167 lines

  1. '
  2. '  MODEM_IO.BAS
  3. '
  4.  
  5. '$INCLUDE: 'MODEM_IO.BI'
  6. '$INCLUDE: 'PCL4B.BI'
  7.  
  8. CONST FALSE = 0
  9. CONST TRUE = NOT FALSE
  10.  
  11. ' echos incoming to screen
  12.  
  13. ' send string to modem & get echo
  14.  
  15. ' wait for Text$
  16.  
  17. ' enter command state
  18. ' NOTE: assumes escape char = '+' & guard time = 1 sec
  19.  
  20. ' hangup phone (in command state)
  21.  
  22. ' wait for continuous quiet (no incoming serial data)
  23.  
  24.  
  25.  Function BreakTest ()
  26.  ' User BREAK ?
  27.  If SioBrkKey() Or SioKeyPress() Then
  28.    Print "User BREAK"
  29.    BreakTest = True
  30.    Exit Function
  31.  End If
  32.  BreakTest = False
  33.  End Function
  34.  
  35.  Function ModemCmdState (ByVal Port)
  36.  ' delay a bit over 1 second
  37.  rc = SioDelay(25)
  38.  ' send Escape Code exactly 3 times
  39.  For I = 1 To 3
  40.    rc = SioPutc(Port, Asc("+"))
  41.    rc = SioDelay(5)
  42.  Next I
  43.  ' delay again
  44.  rc = SioDelay(25)
  45.  End Function
  46.  
  47.  Function ModemEcho (ByVal Port, ByVal Echo)
  48.  Time& = SioTimer&()
  49.  Do While SioTimer&() < Time & Echo
  50.    rc = SioGetc(Port, 1)
  51.    If rc >= 0 Then rc = SioCrtWrite(rc)
  52.  Loop
  53.  End Function
  54.  
  55.  Function ModemHangup (ByVal Port)
  56.  ' enter command state
  57.  rc = ModemCmdState(Port)
  58.  ' hangup !
  59.  rc = ModemSendTo(Port, 4, "!AT!")
  60.  rc = ModemEcho(Port, 10)
  61.  rc = ModemSendTo(Port, 4, "ATH0!")
  62.  End Function
  63.  
  64. Function ModemQuiet (ByVal Port, ByVal Tics)
  65.  ' set up
  66.  CharTime& = SioTimer&()
  67.  Do
  68.    ' User BREAK ?
  69.    If BreakTest() Then
  70.       ModemQuiet = False
  71.       Exit Function
  72.    End If
  73.    ' wait for next character
  74.    Code = SioGetc(Port, 1)
  75.    If Code < -1 Then
  76.       ModemQuiet = False
  77.       Exit Function
  78.    End If
  79.    If Code >= 0 Then
  80.       CharTime& = SioTimer&()
  81.       rc = SioCrtWrite(Code)
  82.    Else
  83.       ' =-1, timed out
  84.       If SioTimer&() >= CharTime& + Tics Then
  85.          ModemQuiet = True
  86.          Exit Function
  87.       End If
  88.    End If
  89.  Loop
  90.  End Function
  91.  
  92.  Function ModemSendTo (ByVal Port, ByVal Pace, Text$)
  93.  For I = 1 To Len(Text$)
  94.    ' User BREAK ?
  95.    If BreakTest() Then
  96.      ModemSendTo = False
  97.      Exit Function
  98.    End If
  99.    ' delay <Pace> tics
  100.    If Pace > 0 Then rc = ModemEcho(Port, Pace)
  101.    ' fetch character
  102.    c$ = Mid$(Text$, I, 1)
  103.    Select Case c$
  104.      Case "!"
  105.        ' replace ! with carriage return
  106.        c$ = Chr$(13)
  107.      Case "~"
  108.        ' delay 1/2 second
  109.        rc = SioDelay(10)
  110.        c$ = " "
  111.      Case " "
  112.        ' delay 1/4 second
  113.        rc = SioDelay(5)
  114.        c$ = " "
  115.    End Select
  116.    ' transmit
  117.    rc = SioPutc(Port, Asc(c$))
  118.  Next I
  119.  ModemSendTo = True
  120.  End Function
  121.  
  122.  Function ModemWaitFor (ByVal Port, ByVal Tics, ByVal CaseFlag, Text$)
  123.  Length = Len(Text$)
  124.  ' wait for string
  125.  Time& = SioTimer&()
  126.  First = 1
  127.  Do While SioTimer&() < Time & Tics
  128.    ' User BREAK ?
  129.    If BreakTest() Then
  130.      ModemWaitFor = False
  131.      Exit Function
  132.    End If
  133.    ' wait for next character
  134.    Code = SioGetc(Port, 1)
  135.    If Code < -1 Then
  136.      ModemWaitFor = False
  137.      Exit Function
  138.    End If
  139.    If Code >= 0 Then
  140.      ' echo char
  141.      rc = SioCrtWrite(Code)
  142.      ' prepare chars
  143.      c1$ = Mid$(Text$, First, 1)
  144.      First = First + 1
  145.      c2$ = Chr$(Code)
  146.      ' case sensitive ?
  147.      If Not CaseFlag Then
  148.        c1$ = UCase$(c1$)
  149.        c2$ = UCase$(c2$)
  150.      End If
  151.      ' does char match ?
  152.      '''PRINT "[";c1$;"|";c2$;"]"
  153.      If c1$ = c2$ Then
  154.        If First > Length Then
  155.          ModemWaitFor = True
  156.          Exit Function
  157.        End If
  158.      Else
  159.        'start over again
  160.        First = 1
  161.      End If
  162.    End If
  163.  Loop
  164.  ModemWaitFor = False
  165.  End Function
  166.  
  167.